import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


class PageFansHeaderCom extends StatefulWidget implements PreferredSizeWidget {
  final String title;
  final void Function() goBack;
  final bool definedGoBack;
  bool showBottomBorder = true;
  bool showGoBackBtn = true;

  PageFansHeaderCom(
      {super.key,
      required this.title,
      this.definedGoBack = false,
      void Function()? goBack,
      this.showBottomBorder = true,
      this.showGoBackBtn = true})
      : goBack = goBack ?? (() {});

  @override
  State<PageFansHeaderCom> createState() => _PageFansHeaderComState();

  @override
  Size get preferredSize => Size(400.w, 44.w); //其实这里的值对最后的高度没有什么影响
}

class _PageFansHeaderComState extends State<PageFansHeaderCom> {
  @override
  Widget build(BuildContext context) {
    final statusBarHeight = MediaQuery.of(context).padding.top;
    // TODO: implement build
    return Container(
      width: double.infinity,
      height: statusBarHeight + 44,
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          bottom: BorderSide(
            color: widget.showBottomBorder
                ? Color.fromRGBO(243, 242, 247, 1)
                : Colors.transparent,
            width: 1.w,
          ),
        ),
      ),
      child: Column(
        children: [
          SizedBox(
            height: statusBarHeight,
          ),
          Expanded(
              flex: 1,
              child: Stack(
                children: [
                  Row(
                    children: [
                      Expanded(
                          flex: 1,
                          child: Container(
                            alignment: Alignment.center,
                            child: Text(
                              widget.title,
                              style: TextStyle(
                                fontSize: 16.sp,
                                fontWeight: FontWeight.w500,
                                color: Color.fromRGBO(51, 51, 51, 1),
                              ),
                            ),
                          ))
                    ],
                  ),
                  if (widget.showGoBackBtn)
                    Positioned(
                      top: 0,
                      left: 0,
                      child: InkWell(
                        onTap: () {
                          if (widget.definedGoBack) {
                            widget.goBack();
                            return;
                          }
                          Navigator.pop(context);
                        },
                        child: Container(
                          child: Image.asset(
                            'assets/images/dapp/history_goback.png',
                            width: 20.w,
                            height: 20.w,
                          ),
                          padding: EdgeInsets.only(
                              left: 15.w, right: 15.w, top: 12.w, bottom: 12.w),
                        ),
                      ),
                    ),
                ],
              ))
          // Expanded(child: child),
        ],
      ),
    );
  }
}
